#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    //close(0);
    //close(2);
    //close(1);

    umask(0);
    //int fd = open("myfile.txt",O_WRONLY | O_CREAT | O_TRUNC,0666);
    //int fd = open("myfile.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    int fd = open("myfile.txt",O_RDONLY,0666);
    if(fd < 0)
    {
        perror("open");
        return -1;
    }
    dup2(fd,0);
    printf("fd:%d\n",fd);
    //fflush(stdout);
    
    char str[101] = {0};
    read(fd,str,sizeof(str)-1);
    printf("%s",str);
    //const char* str = "hello world\n";
    //write(fd,str,strlen(str));

    close(fd);
    return 0;
}
